//
//  ZWShowCityTableViewCell.m
//  WanEr
//
//  Created by 高文萍 on 16/1/17.
//  Copyright © 2016年 ziwokeji. All rights reserved.
//

#import "ZWShowCityTableViewCell.h"
#import "ZWShowCityCollectionViewCell.h"
@implementation ZWShowCityTableViewCell
- (void)createData
{
    [self.baseShowCollecView reloadData];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.baseShowCollecView = [[ZWBaseCollecView alloc]initWithFrame:CGRectZero flowLayoutItemSize:CGSizeMake((WIDTH - 20 * 4) / 3, (WIDTH - 20 * 3) / 3 + (WIDTH - 20 * 4) / 6) xSpace:20 ySpace:0 sectionInset:UIEdgeInsetsMake(20, 20, 20, 20) cell:[ZWShowCityCollectionViewCell class] reuse:@"showReuse"];
        self.baseShowCollecView.delegate = self;
        self.baseShowCollecView.dataSource = self;
        self.baseShowCollecView.scrollEnabled = NO;
        [self.contentView addSubview:self.baseShowCollecView];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    if (self.showArr.count < 4) {
        self.baseShowCollecView.frame = CGRectMake(0, 0, WIDTH, (WIDTH - 20 * 3) / 3 + (WIDTH - 20 * 5) / 6 + 40);
    }else{
        self.baseShowCollecView.frame = CGRectMake(0, 0, WIDTH, ((WIDTH - 20 * 3) / 3 + (WIDTH - 20 * 5) / 6 + 40) * self.showArr.count / 3);
    }
    self.baseShowCollecView.showsVerticalScrollIndicator = NO;
    self.baseShowCollecView.showsHorizontalScrollIndicator = NO;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{

    return self.showArr.count;
    
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    ZWShowCityCollectionViewCell *showCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"showReuse" forIndexPath:indexPath];
    
    [showCell.imgShow sd_setImageWithURL:[NSURL URLWithString:self.showArr[indexPath.row][@"image_url"]]placeholderImage:[UIImage imageNamed:@"筛选后占位图"]];
    showCell.cityShowLabel.text = self.showArr[indexPath.row][@"scenerie_name"];
    showCell.cityDownLabel.text = @"介绍街景";
    [showCell.cityPlayBut setImage:[UIImage imageNamed:@"播放2"] forState:UIControlStateNormal];
    return showCell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    self.collUId = self.showArr[indexPath.row][@"id"];;
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObject:self.collUId forKey:@"id"];
    NSNumber *numPlayer = [NSNumber numberWithUnsignedInteger:indexPath.row];
    [dic setObject:numPlayer forKey:@"index"];
    [[NSNotificationCenter defaultCenter]postNotificationName:@"pushVC" object:nil userInfo:dic];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
